package com.yochi.pictureseditor.activities;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.yochi.pictureseditor.Processor;
import com.yochi.pictureseditor.R;
import com.yochi.pictureseditor.constants.Constants;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.TextView;

public class LoadingPage extends Activity {
	
	private static final String TAG = "LoadingPage";
	
	private TextView tvAppName;
	private AdView adView;
	
	private Handler handler;
	
    @Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loading);
        
        // set app name
        this.tvAppName = (TextView) findViewById(R.id.textView_loading);
        
        // set ads view
        this.adView = (AdView) findViewById(R.id.adView);
        
        Typeface tf;
        int size;
        
//        // set random typeface
//        switch(RandomUtils.randInt(0, 4)) {
//        	case 1:
//                tf = Typeface.createFromAsset(getAssets(), "fonts/game_over.ttf"); 
//                size = 80;
//        		break;
//        		
//        	case 2:
//                tf = Typeface.createFromAsset(getAssets(), "fonts/basscrw.ttf"); 
//                size = 40;
//        		break;
//        		
//        	case 3:
//                tf = Typeface.createFromAsset(getAssets(), "fonts/pixel_bricks.otf"); 
//                size = 60;
//        		break;
//        		
//        	case 4:
//                tf = Typeface.createFromAsset(getAssets(), "fonts/neon.ttf"); 
//                size = 40;
//        		break;
//        		
//        	default: 
//                tf = Typeface.createFromAsset(getAssets(), "fonts/game_over.ttf"); 
//                size = 80;
//                break;
//        }
        tf = Typeface.createFromAsset(getAssets(), "fonts/neon.ttf"); 
        size = 40;
        this.tvAppName.setTypeface(tf);
        this.tvAppName.setTextSize(size);
        
        this.handler = new Handler();
        this.handler.postDelayed(loadedCallback, Constants.LOADING_PAGE_TIME_MS);
        
        // load ads 
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);

    }
    
    private final Runnable loadedCallback = new Runnable() {
		public void run() {
			Log.i(TAG, "loadedCallback");
			handler.removeCallbacks(loadedCallback);
			Intent i = new Intent(LoadingPage.this, Processor.class);
			startActivity(i);
			finish();
		}
    };

}
